import React, { createContext } from 'react'

const { Provider, Consumer: CountConsumer } = createContext()

class CountProvider extends React.Component {

  constructor() {
    super();
    this.state = {
      count: 1
    }
  }

  incrementCount=()=>{
    this.setState({
      count:this.state.count + 1
    })
  }

  decrementCount=()=>{
    this.setState({
      count:this.state.count - 1
    })
  }

  render() {
    return (
      <Provider value={{
        count: this.state.count,
        incrementCount: this.incrementCount,
        decrementCount: this.decrementCount
      }}>
        {
          this.props.children
        }
      </Provider>

    )

  }
}

export {
  CountProvider,
  CountConsumer

};